using UnityEngine;
using System.Collections;

public class Shoot : MonoBehaviour {

    public GameObject Bullet;
    Transform spawn;

    int power;
    float cadencia;
    float contadorTempo;

	// Use this for initialization
	void Start () {
        spawn = transform.Find("BulletSpawn");
        power = Bullet.GetComponent<BulletController>().force;
        cadencia = Bullet.GetComponent<BulletController>().cadencia;
        contadorTempo = 0;
	}
	
	// Update is called once per frame
	void Update () {

        if (Input.GetButton("Fire1"))
        {
            if (Time.time > contadorTempo + cadencia)
            {
                GameObject go = (GameObject)Instantiate(Bullet, spawn.position, spawn.rotation);
                go.rigidbody.AddForce(go.transform.up * power, ForceMode.Impulse);
                contadorTempo = Time.time;
            }
        }
	}
}
